<template>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item v-for="item in fromList" :label="item.title">
            <span v-if="item.type === 'input'">
                <el-input
                    v-model="formInline[item.model]"
                    :placeholder="item.placeholder"
                    clearable
                    @clear="onSubmit('搜索')"
                />
            </span>
            <span v-if="item.type === 'selete'">
                <el-select v-model="formInline[item.model]" :placeholder="item.placeholder">
                    <el-option
                        v-for="seleteItem in item.options"
                        :key="seleteItem[item.seleteValue.key]"
                        :label="seleteItem[item.seleteValue.modelLabel ? item.seleteValue.modelLabel : 'label']"
                        :value="seleteItem[item.seleteValue.modelValue ? item.seleteValue.modelLabel : 'value']"
                    />
                </el-select>
            </span>
            <span v-if="item.type === 'date'">
                <el-date-picker
                    v-model="formInline[item.model]"
                    :type="item.dateType"
                    :placeholder="item.placeholder"
                    :value-format="item.valueFormat"
                />
            </span>
            <span v-if="item.type === 'button'">
                <el-button v-for="btnItem in item.options" type="primary" @click="onSubmit(btnItem.btnName)">
                    {{ btnItem.btnName }}
                </el-button>
            </span>
        </el-form-item>
    </el-form>
</template>

<script setup lang="ts">
import { defineProps, reactive, defineEmits } from 'vue';
let formInline: any = reactive({});
let emit = defineEmits(['searchData', 'addTrue']);
let props = defineProps(['fromList']);

function onSubmit(btnName: string): void {
    switch (btnName) {
        case '搜索':
            emit('searchData', formInline);
            break;
        case '新增':
            emit('addTrue');
            break;
        default:
            break;
    }
}
</script>

<style scoped lang="scss"></style>
